package com.lmk.qs.jdbc;

import com.mysql.jdbc.Driver;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class test01 {
    public static void main(String[] args) throws Exception {
        //1.注册驱动
        DriverManager.registerDriver(new Driver());
        //2.获取数据库连接对象
        Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/kk","root","root");
        //3.定义sql语句
        String sql="select * from emp  ";
        Statement statement=con.createStatement();
        ResultSet rs= statement.executeQuery(sql);
        while (rs.next()){
            System.out.print("id" + "\t" + rs.getString(1));
            System.out.print("\t" +"name" + "\t" + rs.getString(2));
            System.out.print("\t" +"gender" + "\t" + rs.getString(3));
            System.out.print("\t" +"salary" + "\t" + rs.getString(4));
            System.out.print("\t" +"join_date" + "\t" + rs.getString(5));
            System.out.println("\t" +"dept_id" + "\t" + rs.getString(6));


        }

        System.out.println(rs.toString());
        rs.close();
        statement.close();
        con.close();
    }
}
